<?php
$this->breadcrumbs = array(
    'Items' => array('index'),
    'Manage',
);

$this->menu = array(
    array('label' => 'List Item', 'url' => array('index')),
    array('label' => 'Create Item', 'url' => array('create')),
);
?>

<h1>Manage Items</h1>
<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'enableAjaxValidation' => TRUE,
        ));
?>
<script>
    function reloadGrid(data) {
        $.fn.yiiGridView.update('item-grid');
    }
</script>
<?php echo CHtml::ajaxSubmitButton('Hiện', array('item/ajaxUpdate', 'act' => 'doActive'), array('success' => 'reloadGrid')); ?>
<?php echo CHtml::ajaxSubmitButton('Ẩn', array('item/ajaxUpdate', 'act' => 'doInactive'), array('success' => 'reloadGrid')); ?>
<?php echo CHtml::ajaxSubmitButton('Xóa', array('item/ajaxUpdate', 'act' => 'doDelete'), array('success' => 'reloadGrid', 'beforeSend' => 'function(){
            return confirm("Bạn có chắc chắn muốn xóa những Items đã chọn?")
        }',)); ?>
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'item-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        array(
            'id' => 'autoId',
            'class' => 'CCheckBoxColumn',
            'selectableRows' => '50',
        ),
        array(
            'name' => 'id',
            'header' => 'ID',
            'htmlOptions' => array('style' => 'width:50px;')
        ),
        array(
            'name' => 'avatar',
            'header' => 'Ảnh',
            'type' => 'raw',
            'value' => 'CHtml::image(Yii::app()->request->baseUrl.\'/upload/admin/items/\'.$data->avatar,"",array("style"=>"width:50px;"))'
        ),
        'name',
        array(
            'name' => 'status',
            'header' => 'Trạng thái',
            'filter' => array('1' => 'Hiển thị', '0' => 'Ẩn'),
            'value' => '($data->status=="1")?("Hiển thị"):("Ẩn")'
        ),
        array(
            'name' => 'user_created',
            'header' => 'Người tạo',
            'value' => '$data->userCreated->fullname'
        ),
        'created_at',
        array(
            'class' => 'bootstrap.widgets.TbButtonColumn',
        ),
    ),
));
?>
<?php $this->endWidget(); ?>
